package com.LeeCode;

/**
 * 奇偶频次间的最大差值 I
 */

public class Code3442 {
    public static void main(String[] args) {
        String s = "mmsmsym";
        System.out.println(new Code3442().maxDifference(s));
    }

    public int maxDifference(String s) {
        int[] cnt = new int[26];
        char[] chars = s.toCharArray();
        for (char c : chars) {
            cnt[c - 'a']++;
        }

        int oddCnt = 0, evenCnt = Integer.MAX_VALUE;

        for (int i = 0; i < cnt.length; i++) {
            if (cnt[i] == 0) continue;

            if (cnt[i] % 2 == 0) {
                evenCnt = Math.min(evenCnt, cnt[i]);
            } else {
                oddCnt = Math.max(oddCnt, cnt[i]);
            }
        }
        return oddCnt - evenCnt;
    }
}
